# -*- coding: utf-8 -*-
# @Time    : 2023/10/12 13:41
# @Author  : floraachy
# @File    : login_api.py
# @Software: PyCharm
# @Desc:

# 本地应用/模块导入
from case_utils.base_request import BaseRequest
from case_utils.tools import url_handle


def login_api(host, user, pwd):
    """
    登录接口
    请求地址：{host}/api/accounts/login.json
    请求方法：POST
    请求头：{"Content-Type": "application/json;charset=UTF-8"}
    请求参数：
        {
        "login": {user},    # 用户名
        "password": {pwd},  # 密码
        "autologin": 1    # 前端是否勾选自动登录
        }
    """

    req_data = {
        "title": "登录接口",
        "url": url_handle(host=host, url="/api/accounts/login.json"),
        "method": "POST",
        "headers": {"Content-Type": "application/json;charset=UTF-8"},
        "request_type": "json",
        "payload": {"login": user, "password": pwd,
                    "autologin": 1}
    }
    return BaseRequest.send_request(req_data)
